﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using log4net;
using AutoFacUtils;
using Common;
using CashFlow.Web.Filters;
using CashFlow.Web.Common;
using CashFlow.Web.Def;
using CashFlow.Web.Areas.SystemManage.Models;
using CashFlow.Web.Areas.SystemManage.Models.Shop;
using CashFlow.Web.Areas.SystemManage.Validator;
using CashFlow.Web.Areas.SystemManage.Validator.Shop;
using IShopService3 = CashFlow.Web.Areas.SystemManage.Service.IShopService;
using IUserService3 = CashFlow.Web.Areas.SystemManage.Service.IUserService;

namespace CashFlow.Web.Areas.SystemManage.Controllers
{
    [RootUserFilter]
    public class ShopController : Controller
    {
        private static ILog _logger = LogManager.GetLogger(typeof(ShopController));
        private IShopService3 GetShopService3() { return AutoFacHelper.Get<IShopService3>(); }
        private IUserService3 GetUserService3() { return AutoFacHelper.Get<IUserService3>(); }

        // GET: SystemManage/Shop
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        [ValidatorFilter(typeof(QueryShopModelValidator))]
        public ActionResult QueryByWhere(QueryShopModel model)
        {
            var service3 = GetShopService3();
            var ls = service3.QueryByWhere(model.Name);
            return MyCommonTool.CreateOperationResult(true, "", ls);
        }

        [HttpPost]
        [ValidatorFilter(typeof(NewShopModelValidator))]
        public ActionResult NewShop(NewShopModel model)
        {
            var service3 = GetShopService3();
            var result = service3.NewShop(
                            model.ShopManagerUserId
                            , model.ShopName
                            , model.ShopNo
                         );
            return MyCommonTool.CreateOperationResult(
                        result == ENewShopResult.Success
                        , EnumTool.GetDescription<ENewShopResult, int>(result)
                        , null
                   );
        }

        [HttpPost]
        [ValidatorFilter(typeof(QueryShopUserModelValidator))]
        public ActionResult QueryShopUsersByShopManagerUserId(
            QueryShopUserModel model)
        {
            var service3 = GetUserService3();
            var ls = service3.QueryShopUsersByShopManagerUserIdByWhere(
                        model.ShopManagerUserId
                        , model.Name
                        , model.Phone
                     );
            return MyCommonTool.CreateOperationResult(true, "", ls);
        }
    }
}